<?php

/**
 * 获取所有节点
 * @param  boolean $reload [description]
 * @return [type]          [description]
 */
function getNodes($refresh=false){
	if ($refresh) {
		think\Cache::rm('adminNodes');
	}
	$nodes=think\Cache::get('adminNodes');
	if (!$nodes) {
		$nodes=think\Db::name('admin_rule')->where(array('status'=>1))->select();
		think\Cache::set('adminNodes',$nodes);
	}
	return $nodes;
}

/**
 * 通过节点code获取 当前节点
 * @param  [type]  $code    [description]
 * @param  boolean $refresh [description]
 * @return [type]           [description]
 */
function getNodeByCode($code,$refresh=false){
	$nodes=getNodes($refresh);
	foreach ($nodes as $k => $v) {
		if ($v['code']==$code) {
			break;
		}
	}
	return $v;
}

/**
 * 通过节点id获取 当前节点
 * @param  [type]  $code    [description]
 * @param  boolean $refresh [description]
 * @return [type]           [description]
 */
function getNodeById($code,$refresh=false)
{
	$nodes=getNodes($refresh);
	foreach ($nodes as $k => $v) {
		if ($v['id']==$code) {
			break;
		}
	}
	return $v;
}